<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
      <#include "/common/elibs.html">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  </head>
  <script>var index;
  </script><body>
    <div class="x-body">
        <form class="layui-form">
            <input type="hidden" name="idxProAdmin" id="idxProAdmin" value="${id}"/>
            <input type="hidden" name="idProPowerSupplyScheme" id="idProPowerSupplyScheme" value="${subsetId}"/>
            <input type="hidden" name="paramsType" id="paramsType" value="${type}"/>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    开始时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="beginTime" name="beginTime"
                           autocomplete="off" class="layui-input" disabled style="background-color: #b7b1b1;">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    结束时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="endTime" name="endTime"
                           autocomplete="off" class="layui-input" disabled style="background-color: #b7b1b1;">
                </div>
            </div>

            <div class="layui-form-item" id="difference">
                <label class="layui-form-label">
                    距离结束时间天数
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="differenceTime" name="differenceTime"
                           autocomplete="off" class="layui-input" disabled style="background-color: #b7b1b1;">
                </div>
            </div>

            <div class="layui-form-item" id="powerSupply" style="padding: 20px; background-color: #F2F2F2;">

            </div>




            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" type=button lay-submit="">
                    提交
                </button>
            </div>
      </form>
    </div>
    <script>
        var countDigit = 1;
        function powerSupply(){
            var html = ' <div class="layui-col-md6 powerSupply" style="width: 100%;">\n' +
                '                    <div class="layui-card">\n' +
                '                        <div class="layui-card-header">\n' +
                '                            电源数据\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label class="layui-form-label">电源情况</label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                供电单位拟向客户提供\n' +
                '<input type="hidden" class="powerSupply" value>' +
                '                                <input type="radio" name="powerSupply'+countDigit+'" lay-verify="otherReq" lay-filter="powerSupply" value="1" title="单回路" />\n' +
                '                                <input type="radio" name="powerSupply'+countDigit+'" lay-verify="otherReq" lay-filter="powerSupply" value="2" title="双回路" />\n' +
                '                                <input type="radio" name="powerSupply'+countDigit+'" lay-verify="otherReq" lay-filter="powerSupply" value="3" title="双电流" />\n' +
                '                                <input type="radio" name="powerSupply'+countDigit+'" lay-verify="otherReq" lay-filter="powerSupply" value="4" title="多电流三相交流、50Hz电源。" />\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>电源性质 </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="powerProperties" name="powerProperties" lay-verify="required"  placeholder="请输入" autocomplete="off" class="layui-input" />\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>电源类型 </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '<input type="hidden" class="powerType" value>' +
                '                                <input type="radio" name="powerType'+countDigit+'" lay-verify="otherReq" lay-filter="powerType" value="0" title="专线" />\n' +
                '                                <input type="radio" name="powerType'+countDigit+'" lay-verify="otherReq" lay-filter="powerType" value="0" title="公线" />\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>供电电压（kV） </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="powerVoltage" name="powerVoltage" lay-verify="required"  placeholder="请输入" autocomplete="off" class="layui-input" />\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>供电容量（kVA） </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="powerCapacity" name="powerCapacity" lay-verify="required"  placeholder="请输入" autocomplete="off" class="layui-input" />\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>电源接入点 </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="powerSpot" name="powerSpot" lay-verify="required"  placeholder="请输入" autocomplete="off" class="layui-input" />\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>线路参数 -- 电杆选择 </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="lineParameters1" name="lineParameters1" lay-verify="required"  placeholder="请输入" autocomplete="off" class="layui-input" />\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>线路参数 -- 导线选择 </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="lineParameters2" name="lineParameters2" lay-verify="required"  placeholder="请输入" autocomplete="off" class="layui-input" />\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>线路路径及敷设方式<br />\n' +
                '                                <div style="color: #797474;margin-top: 9px;"></div> </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                供电线路路径以设计勘查结果和政府相关部门最终批复为准，线路以\n' +
                '                                <br />\n' +
                '<input type="hidden" class="layingMethod" value>' +
                '                                <input type="checkbox" id="layingMethod'+countDigit+'" name="layingMethod'+countDigit+'" value="1" lay-verify="otherReq" lay-filter="layingMethod" title="排管" />\n' +
                '                                <input type="checkbox" id="layingMethod'+countDigit+'" name="layingMethod'+countDigit+'" value="2" lay-verify="otherReq" lay-filter="layingMethod" title="电缆沟" />\n' +
                '                                <input type="checkbox" id="layingMethod'+countDigit+'" name="layingMethod'+countDigit+'" value="3" lay-verify="otherReq" lay-filter="layingMethod" title="电缆隧道敷设" />\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>系统接地方式<br /> </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '<input type="hidden" class="groundingMode" value>' +
                '                                <input type="radio" name="groundingMode'+countDigit+'" lay-verify="otherReq" lay-filter="groundingMode" value="1" title="不接地" />\n' +
                '                                <input type="radio" name="groundingMode'+countDigit+'" lay-verify="otherReq" lay-filter="groundingMode" value="2" title="经小电阻接地" />\n' +
                '                                <input type="radio" name="groundingMode'+countDigit+'" lay-verify="otherReq" lay-filter="groundingMode" value="3" title="经消弧线圈接地" />\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>接入点系统短路容量 </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="shortCircuitCapacity" name="shortCircuitCapacity" lay-verify="required"  placeholder="请输入" autocomplete="off" class="layui-input" />\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="powerProperties" class="layui-form-label"> <span class="x-red">*</span>产权分界点 </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="pointPropertyRight" name="pointPropertyRight" lay-verify="required"  placeholder="请输入" autocomplete="off" class="layui-input"  />\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <div class="layui-btn" type="button" onclick="powerSupply()">\n' +
                '                                添加电源信息\n' +
                '                            </div>\n' +
                '                            <div class="layui-btn" type="button" onclick="deleteTemp(this)">\n' +
                '                                删除当前电源信息\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                    </div>\n' +
                '                </div>' ;
            $("#powerSupply").append(html);
            countDigit++;
            renderForm();
        }


        function deleteTemp(o){
            $(o).parent().parent().parent().remove();
        }

        $(function(){
            getProTime($("#idxProAdmin").val(),20);
            var type = $("#paramsType").val();
            if(type === 'edit'){
                ajaxFunJson('POST','/pc/project/getPowerSupplySchemeInfo',JSON.stringify({"idProAdmin":$("#idxProAdmin").val()}),function(data){
                    if(data.code != 0){
                        alertFun(data);
                    }else{
                        var proPowerSupplySchemePowerAssList = data.data.proPowerSupplySchemePowerAssList;
                        var j=0;
                        for(var i=0;i<proPowerSupplySchemePowerAssList.length;i++){
                            powerSupply();
                            if(isNotNull(proPowerSupplySchemePowerAssList[i])){
                                if(isNotNull(proPowerSupplySchemePowerAssList[i].powerSupply) || proPowerSupplySchemePowerAssList[i].powerSupply === 0) {
                                    $(".layui-card").children(".layui-form-item").children(".layui-input-inline")
                                        .children("input[name=powerSupply"+(i+1)+"][value="+proPowerSupplySchemePowerAssList[i].powerSupply+"]").prop("checked","true");
                                }
                                if(isNotNull(proPowerSupplySchemePowerAssList[i].powerType) || proPowerSupplySchemePowerAssList[i].powerType === 0) {
                                    $(".layui-card").children(".layui-form-item").children(".layui-input-inline")
                                        .children("input[name=powerType"+(i+1)+"][value="+proPowerSupplySchemePowerAssList[i].powerType+"]").prop("checked","true");
                                }
                                if(isNotNull(proPowerSupplySchemePowerAssList[i].groundingMode) || proPowerSupplySchemePowerAssList[i].groundingMode === 0) {
                                    $(".layui-card").children(".layui-form-item").children(".layui-input-inline")
                                        .children("input[name=groundingMode"+(i+1)+"][value="+proPowerSupplySchemePowerAssList[i].groundingMode+"]").prop("checked","true");
                                }
                                renderForm();
                            }
                        }
                        $(".layui-card").each(function(){
                            $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=powerProperties]").val(proPowerSupplySchemePowerAssList[j].powerProperties);
                            $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=powerVoltage]").val(proPowerSupplySchemePowerAssList[j].powerVoltage);
                            $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=powerCapacity]").val(proPowerSupplySchemePowerAssList[j].powerCapacity);
                            $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=powerSpot]").val(proPowerSupplySchemePowerAssList[j].powerSpot);
                            $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=lineParameters1]").val(proPowerSupplySchemePowerAssList[j].lineParameters1);
                            $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=lineParameters2]").val(proPowerSupplySchemePowerAssList[j].lineParameters2);
                            $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=shortCircuitCapacity]").val(proPowerSupplySchemePowerAssList[j].shortCircuitCapacity);
                            $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=pointPropertyRight]").val(proPowerSupplySchemePowerAssList[j].pointPropertyRight);

                            if(isNotNull(proPowerSupplySchemePowerAssList[j].powerSupply) || proPowerSupplySchemePowerAssList[j].powerSupply === 0) {
                                $(this).children(".layui-form-item").children(".layui-input-inline").children(".powerSupply").val(proPowerSupplySchemePowerAssList[j].powerSupply);
                            }
                            if(isNotNull(proPowerSupplySchemePowerAssList[j].powerType) || proPowerSupplySchemePowerAssList[j].powerType === 0) {
                                $(this).children(".layui-form-item").children(".layui-input-inline").children(".powerType").val(proPowerSupplySchemePowerAssList[j].powerType);
                            }
                            if(isNotNull(proPowerSupplySchemePowerAssList[j].groundingMode) || proPowerSupplySchemePowerAssList[j].groundingMode === 0) {
                                $(this).children(".layui-form-item").children(".layui-input-inline").children(".groundingMode").val(proPowerSupplySchemePowerAssList[j].groundingMode);
                            }

                            var layingMethod = proPowerSupplySchemePowerAssList[j].layingMethod.split(",");
                            for(var b=0;b<layingMethod.length;b++){
                                var unitTypeCheckbox = $("input[id='layingMethod"+(j+1)+"']");
                                for(var a=0;a<unitTypeCheckbox.length;a++){
                                    if(unitTypeCheckbox[a].value == layingMethod[b]){
                                        unitTypeCheckbox[a].checked = true;
                                    }
                                }
                            }
                            renderForm();

                            j++;
                        })
                    }
                })
            }else if(type === 'add'){
                powerSupply();
            }
        })

        layui.use(['form','layer'], function() {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer, layedit = layui.layedit;

            //自定义验证规则
            form.verify({
                otherReq: function(value,item){
                    var $ = layui.$;
                    var verifyName=$(item).attr('name')
                        , verifyType=$(item).attr('type')
                        ,formElem=$(item).parents('.layui-form')//获取当前所在的form元素，如果存在的话
                        ,verifyElem=formElem.find('input[name='+verifyName+']')//获取需要校验的元素
                        ,isTrue= verifyElem.is(':checked')//是否命中校验
                        ,focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
                    if(!isTrue || !value) {
                        //定位焦点
                        focusElem.css(verifyType == 'radio' ? {"color": "#FF5722"} : {"border-color": "#FF5722"});
                        //对非输入框设置焦点
                        focusElem.first().attr("tabIndex", "1").css("outline", "0").blur(function () {
                            focusElem.css(verifyType == 'radio' ? {"color": ""} : {"border-color": ""});
                        }).focus();
                        return '必填项不能为空';
                    }
                }
            });



            form.on('radio(powerSupply)', function (data) {
                $(this).siblings(".powerSupply").val(data.value);
            })
            form.on('radio(powerType)', function (data) {
                $(this).siblings(".powerType").val(data.value);
            })
            form.on('radio(groundingMode)', function (data) {
                $(this).siblings(".groundingMode").val(data.value);
            })

            //添加电源信息
            layui.$('#addPowerSupply').on('click', function(){
                powerSupply();
            });



            //监听提交
            form.on('submit(add)', function (t) {
                var data = form.val('example');
                addSubmit(data);
            });

        });

        function addSubmit(data){

            var myArray=new Array(),i = 0;
            $(".layui-card").each(function(){
                var data = {
                    "powerProperties": $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=powerProperties]").val(),
                    "powerVoltage": $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=powerVoltage]").val(),
                    "powerCapacity": $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=powerCapacity]").val(),
                    "powerSpot": $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=powerSpot]").val(),
                    "lineParameters1": $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=lineParameters1]").val(),
                    "lineParameters2": $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=lineParameters2]").val(),
                    "shortCircuitCapacity": $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=shortCircuitCapacity]").val(),
                    "pointPropertyRight": $(this).children(".layui-form-item").children(".layui-input-inline").children("input[name=pointPropertyRight]").val(),

                    "powerSupply": $(this).children(".layui-form-item").children(".layui-input-inline").children(".powerSupply").val(),
                    "powerType": $(this).children(".layui-form-item").children(".layui-input-inline").children(".powerType").val(),
                    "groundingMode": $(this).children(".layui-form-item").children(".layui-input-inline").children(".groundingMode").val(),

                    "layingMethod":GetCheckboxValues("layingMethod"+(i+1))

                }
                myArray[i] = data;
                i++;
            })
            var params = {
                //tcaDescribe : layui.layedit.getContent(index),
                "idProAdmin": $("#idxProAdmin").val(),
                "idProPowerSupplyScheme":$("#idProPowerSupplyScheme").val(),
                "proPowerSupplySchemePowerAssList":myArray,
            }
            if (true) {
                ajaxFunJson('post','/pc/project/updatePowerSupplyScheme',JSON.stringify(params),function(data){
                    if (data.code != 0) {
                        alertFun(data);
                    } else {
                        window.location.href = path + "/modules/project/onePro/zdgdfa/list.html";
                        console.log("success !");
                    }
                })
                return false;
            }
        }

        //将checke拼接为"value1,value2,value3"

        function GetCheckboxValues(Name) {
            var result = [];
            $("[id='" + Name + "']:checkbox").each(function () {
                if ($(this).is(":checked")) {
                    result.push($(this).attr("value"));
                }
            });
            return result.join(",");
        };
    </script></body></html>